package cn.netjava.robo3d;

import java.text.DecimalFormat;

import cn.netjava.robo3d.device.Atlas;

import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jmex.font2d.Font2D;
import com.jmex.font2d.Text2D;

public class DashBoard extends Node {

	private int Gear;
	private float Maxoilrate;
	private float oilrate;
	private Text2D showoilrate;
	private Text2D showspeed;
	
	private Text2D show_score_blood;
	private Text2D show_bulletnum_firenum;
	private Text2D show_byshoot_byfire;
	
	private String textspeed;
	private String bar;
	private RoboTank car;
	private Font2D font;
	private DecimalFormat df;
	
	public DashBoard(RoboTank car){
		this.setName("panelboard");
		this.oilrate=car.getoilrate();
		this.car=car;
		Maxoilrate=car.getMaxoilrate();
		df=new DecimalFormat("#.##");
		font=new Font2D();
        showoilrate=font.createText("", 20, 1);
        showspeed=font.createText("", 20, 1);
        show_score_blood=font.createText("", 2, 1);
        show_bulletnum_firenum=font.createText("",20,1);
        show_byshoot_byfire=font.createText("",20,1);
        showoilrate.setLocalTranslation(new Vector3f(0,15,0));
        show_score_blood.setLocalTranslation(new Vector3f(0,30,0));
        show_bulletnum_firenum.setLocalTranslation(new Vector3f(0,45,0));
        show_byshoot_byfire.setLocalTranslation(new Vector3f(0,60,0));
        
        Text2D test=font.createText("测试中文，", 20, 1);
        test.setLocalTranslation(new Vector3f(0,100,0));
        this.attachChild(test);
        
        this.attachChild(showspeed);       
        this.attachChild(showoilrate);
        
        this.attachChild(show_score_blood); 
        this.attachChild(show_bulletnum_firenum);  //子弹和火的个数;
        this.attachChild(show_byshoot_byfire);        //中弹次数
        
		bar="";
		updatetext();
	}
	
	public void updatetext(){
//		System.out.println("刷新仪表盘");
		double count=car.getoilrate()*3;
		String num=df.format(car.getoilrate());
		if(car.getoilrate()==0){
			   num="0.00";
			}
		if(car.getoilrate()==car.getMaxoilrate()){
			num=""+car.getMaxoilrate();
		}
		String oiltext="[Gear:"+car.getGear()+"]throttle :("+num+")";
        count=Math.floor(count);
           bar="";
        for(int i=0;i<count;i++){
        	bar=bar+"|";
        }
        if(car.getoil()<0.2){
        	bar="out of gas";
        	showoilrate.setLocalScale(1.7f);
            oiltext="[Gear:"+Gear+"]throttle:(0) ";
        }       
        oiltext=oiltext+bar;
        showoilrate.setText(oiltext);
        
        textspeed="car speed:"+df.format(car.getspeed());
        textspeed=textspeed+"          total oil:"+df.format(car.getoil())+"";
        showspeed.setText(textspeed);
        
        String sbtxt;
        sbtxt="MyScore : "+car.getinfo().getScore()+"    MyBlood : "+car.getinfo().getBlood();
        show_score_blood.setText(sbtxt);
        
        String bftxt;
        bftxt="MyBulletnum : "+car.getinfo().getBulletnum()+"   MyfireGunOilnum : "+car.getinfo().getFirenum();
        show_bulletnum_firenum.setText(bftxt);
        
        String sftxt;
        sftxt="ByOther shoot : "+car.getinfo().getByshoot()+"   ByOtherfirehit : "+car.getinfo().getByfire();
        show_byshoot_byfire.setText(sftxt);
	}

}
